package com.wuliu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wuliu.common.core.domain.ApiResult;
import com.wuliu.common.core.domain.entity.BasCust;
import com.wuliu.common.core.domain.entity.SysDept;
import com.wuliu.common.utils.SecurityUtils;
import com.wuliu.common.utils.StringUtils;
import com.wuliu.system.mapper.SysDeptMapper;
import com.wuliu.system.service.ISysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author realue
 * @version 1.0
 * @date 2023-10-31 11:35
 */

@RestController
@RequestMapping("/applet/dept")
@Api(tags = {"站点控制器"})
public class SysDeptController {

    @Resource
    private SysDeptMapper sysDeptMapper;

    @GetMapping("/list")
    @ApiOperation(value = "查询站点列表", notes = "")
    @ApiImplicitParam(name = "key", value = "关键字(站点编号/站点名称/负责人/负责人电话)", dataType = "String", paramType = "query")
    public ApiResult<List<SysDept>> list(String key) {
        BasCust user = SecurityUtils.getBasCust();
        QueryWrapper<SysDept> wrapper = new QueryWrapper<>();
        wrapper.eq("sys_account", user.getSysAccount());
        if (StringUtils.isNotEmpty(key)) {
            wrapper.and(qw -> qw.like("dept_name", key)
                    .or().like("dept_no", key)
                    .or().like("leader", key)
                    .or().like("phone", key));
        }
        return ApiResult.success(sysDeptMapper.selectList(wrapper));
    }
}
